package com.yemast.bluetoothtest

import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothClass
import android.bluetooth.BluetoothDevice
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log


class BlueReceiver : BroadcastReceiver() {

    private val pin = "0000"  //此处为你要连接的蓝牙设备的初始密钥，一般为1234或0000

    private val TAG = "mcy_Receiver"
    //    private val callBack: ClientCallBack? = null
    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent!!.action
        Log.e("tag", "action==$action");

        val device = intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
        when (action) {
            BluetoothAdapter.ACTION_DISCOVERY_STARTED -> {
                Log.e("tag", "扫描开始");

            }//开始
            BluetoothAdapter.ACTION_DISCOVERY_FINISHED -> {
                Log.e("tag", "扫描结束");

            }//结束
            BluetoothDevice.ACTION_FOUND -> {
                Log.e("tag", "name==${device.name},adress==${device.address}");
                Log.e("tag", "type==${device.bluetoothClass.deviceClass}");
                when (device.bluetoothClass.majorDeviceClass) {
                    BluetoothClass.Device.Major.AUDIO_VIDEO -> {
                        Log.e("tag", "音频");
                    }
                    BluetoothClass.Device.Major.PHONE -> {
                        Log.e("tag", "手机");

                    }
                    BluetoothClass.Device.Major.MISC -> {
                        Log.e("tag", "音乐");
                    }
                    else -> {
                        Log.e("tag", "未知");
                    }
                }


            }//扫描中
            BluetoothDevice.ACTION_PAIRING_REQUEST -> {
            }//配对请求
            BluetoothDevice.ACTION_BOND_STATE_CHANGED -> {
            }//配对状态
        }


    }


}